<?php

namespace AdminPanel\ContractBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

use AdminPanel\DashboardBundle\Utils\adminCustomClass;

class ContractController extends Controller
{

  public function listAction()
  {
    if (isset($_POST['beginDate'])) {
      $beginDate = adminCustomClass::clear($_POST['beginDate']);
    } else {
      $beginDate = date('Y-m-d', strtotime("-1 month"));
    }

    if (isset($_POST['endDate'])) {
      $endDate = adminCustomClass::clear($_POST['endDate']);
    } else {
      $endDate = date('Y-m-d', strtotime("now"));
    }

    if (isset($_POST['type'])) {
      $type = adminCustomClass::clear($_POST['type']);
    } else {
      $type = null;
    }

    if (isset($_POST['tutor'])) {
      $tutor = adminCustomClass::clear($_POST['tutor']);
    } else {
      $tutor = null;
    }

    if (isset($_POST['student'])) {
      $student = adminCustomClass::clear($_POST['student']);
    } else {
      $student = null;
    }

    if (isset($_POST['page'])) {
      $page = adminCustomClass::clear($_POST['page']);
    } else {
      $page = 1;
    }

    $perPage = $this->container->getParameter('perPage');

    $contractList = $this->getDoctrine()->getManager()->getRepository('AdminPanelDashboardBundle:Contract')->findContracts($page, $perPage, $beginDate, $endDate, $type, $tutor, $student);

    $totalContractCount = $this->getDoctrine()->getManager()->getRepository('AdminPanelDashboardBundle:Contract')->findContractsCount($beginDate, $endDate, $type, $tutor, $student);

    $tutorList = $this->getDoctrine()->getManager()->getRepository('AdminPanelDashboardBundle:Tutor')->findAllTutorForSelect();
    $studentList = $this->getDoctrine()->getManager()->getRepository('AdminPanelDashboardBundle:User')->findAllUserForSelect();

    return $this->render('AdminPanelContractBundle:Contract:list.html.twig', array(
                "contractList" => $contractList,
                "totalContractCount" => $totalContractCount,
                "tutorList" => $tutorList,
                "studentList" => $studentList,
                "page" => $page,
                "beginDate" => $beginDate,
                "endDate" => $endDate,
                "type" => $type,
                "tutor" => $tutor,
                "student" => $student,
            ));
  }

  public function statusNameChangeAction($status)
  {

    switch ($status) {
      case 'created' : {
          $result = '<button style="font-size: 9px;width: 70px;" class="btn btn-block btn-warning">Үүсгэсэн</button>';          
          break;
        }
      case 'complete' : {
          $result = '<button style="font-size: 9px;width: 70px;" class="btn btn-block btn-success">Болсон</button>';
          break;
        }
      case 'userDenied' : {
          $result = '<button style="font-size: 9px;width: 90px;" class="btn btn-block btn-danger">Сурагч татгалзсан</button>';
          break;
        }
      case 'tutorCanceled' : {
          $result = 'Багш цуцалсан';
          break;
        }
      case 'userCanceled' : {
          $result = 'Сурагч цуцалсан';
          break;
        }
      case 'adminDenied' : {
          $result = 'Админ татгалзсан';
          break;
        }
      case 'deleted' : {
          $result = 'Устгасан';
          break;
        }
      default : {
          $result = '';
          break;
        }
    }
    
    return new Response($result);
    
  }

}
